﻿package  com.devilcat.ws{
	import com.devilcat.ws.Basicws;
	import com.worlize.websocket.*;
	import com.devilcat.dt.Gamedt;
	
	public class UserIntervalws extends Basicws{
		public function UserIntervalws() {
			super("iw-protocol");
		}
		override function handleWebSocketOpen(event:WebSocketEvent):void
		{
		}
		public function checkToken(){
			var pack:Object = new Object();
			pack.uid=Gamedt.Player.uid;
			pack.token=Gamedt.Player.token;
			pack.status=Gamedt.Player.status;
			pack.action="userinterval";
			var myJson:String = JSONString(pack);
			websocket.sendUTF(myJson);			
		}
		override function handleWebSocketMessage(event:WebSocketEvent):void
		{
			if (event.message.type === WebSocketMessage.TYPE_UTF8)
			{	
				var dumpo:Object = JSONObject(event.message.utf8Data);
				if(dumpo.error=="false"){
					Gamedt.MainUI.errorToken();
				}
				if(dumpo.error=="ok"){
					Gamedt.MainUI.txtpvpid.text=dumpo.pvpid;
					if(Gamedt.MainUI.txtpvpid.text  == "0"){
						Gamedt.MainUI.acceptpvp.gotoAndStop(1);
						//Gamedt.MainUI.endpvpbtn.x=3000;
					}else{
						Gamedt.MainUI.acceptpvp.gotoAndStop(2);
						//Gamedt.MainUI.endpvpbtn.x=769;
					}
				}
			}
		}

	}
	
}
